package mobi.weq.servlets.data;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mobi.weq.dao.PollutionData;
import mobi.weq.model.SensorObservation;

import com.google.gson.Gson;

/**
 * Servlet implementation class
 */
@WebServlet("/data/historical-data-for-location")
public class GetLastNDaysDataForALocation extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// lat, long
		// grid id
		String days = request.getParameter("days");
		String gridId = request.getParameter("gridId");
		Gson g = new Gson();
		// try {
		// response.getWriter().print(g.toJson(PollutionData.getCurrentDataForPosition(Double.valueOf(latString),
		// Double.valueOf(lngString))));
		// } catch (NumberFormatException e) {
		// e.printStackTrace();
		// } catch (SQLException e) {
		// e.printStackTrace();
		// }

		int n = Integer.parseInt(days);
		ArrayList<SensorObservation> obs = PollutionData.getDummySensorObservationLastNDays(n, 0, 0);
		response.getWriter().print(g.toJson(obs));
	}

}
